<?php
    require_once("$CFG->dirroot/mod/aca/lib.php");

    if (empty($form->name)) {
        $form->name = "";
    }
    if (empty($form->description)) {
        $form->description = "";
    }
    if (empty($form->format)) {
        $form->format = "";
    }
    if (empty($form->langtype)) {
        $form->langtype = 0;
    }
    if (empty($form->showtest)) {
        $form->showtest = 0;
    }
    if (empty($form->showcopy)) {
        $form->showcopy = 0;
    }
    if (!isset($form->grade)) {
        $form->grade = 100;
    }
    // default timedue is one week
    if (!isset($form->timedue)) {
        $form->timedue = time()+7*24*3600;
    }
    // defult time id now
    if (!isset($form->timeavailable)) {
        $form->timeavailable = time();
    }
    if (!isset($form->preventlate)) {
        $form->preventlate = 0;
    }
    if (empty($form->maxbytes)) {
        $form->maxbytes = $CFG->aca_maxbytes;
    }
    
?>
<script type="text/javascript" language="javascript">
    var dueitems = ['dueday','duemonth','dueyear','duehour', 'dueminute', 'preventlate'];
    var availableitems = ['availableday','availablemonth','availableyear','availablehour', 'availableminute'];
</script>

<form name="form" method="post" action="../mod/aca/details.php">	
<table cellpadding="5">
<tr valign="top">
    <td align="right"><b><?php print_string("acaname", "aca") ?>:</b></td>
    <td>
        <input type="text" name="name" size=60 value="<?php p($form->name) ?>">
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php print_string("description", "aca") ?>:</b>
     <br /><br />
     <?php
        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
        echo "<br />";
        helpbutton("questions", get_string("helpquestions"), "moodle", true, true);
        echo "<br />";
        if ($usehtmleditor) {
           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
        } else {
           emoticonhelpbutton("form", "description");
        } 
      ?>
    </td>
    <td>
    <?php
       print_textarea($usehtmleditor, 20, 60, 680, 400, "description", $form->description);
    
       if ($usehtmleditor) {
           echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
       } else {
           echo '<div align="right">';
           helpbutton("textformat", get_string("formattexttype"));
           print_string("formattexttype");
           echo ':&nbsp;';
           if (!$form->format) {
               $form->format = $defaultformat;
           }
           choose_from_menu(format_text_menu(), "format", $form->format, ""); 
           echo '</div>';
       }
    ?>
    </td>
</tr>
<tr valign=top>
<td align="right"><b><?php print_string("grade") ?>:</b></td>
    <td>
        <?php
        print_grade_menu($course->id, "grade", "$form->grade");
        ?>
    </td>
</tr>

<tr valign=top>
   <td align="right"><b><?php print_string("availabledate","aca") ?>:</b></td>
    <td>
        <input name="availableenable" type="checkbox" value="1" alt="<?php print_string('availabledate', 'aca') ?>" onclick="return lockoptions('form', 'availableenable', availableitems)" <?php if ($form->timeavailable) echo 'checked="checked"' ?> />
    <?php
           print_date_selector("availableday", "availablemonth", "availableyear", $form->timeavailable);
           echo "&nbsp;-&nbsp;";
           print_time_selector("availablehour", "availableminute", $form->timeavailable);
    ?>
        <input type="hidden" name="havailableday"    value="0" />
        <input type="hidden" name="havailablemonth"  value="0" />
        <input type="hidden" name="havailableyear"   value="0" />
        <input type="hidden" name="havailablehour"   value="0" />
        <input type="hidden" name="havailableminute" value="0" />
    </td>
</tr>

<tr valign=top>
    <td align="right"><b><?php print_string("duedate", "aca") ?>:</b></td>
    <td>
        <input name="dueenable" type="checkbox" value="1" alt="<?php print_string('duedate', 'aca') ?>" onclick="return lockoptions('form', 'dueenable', dueitems)" <?php if ($form->timedue) echo 'checked="checked"' ?> />
    <?php
           print_date_selector("dueday", "duemonth", "dueyear", $form->timedue);
           echo "&nbsp;-&nbsp;";
           print_time_selector("duehour", "dueminute", $form->timedue);
    ?>
        <input type="hidden" name="hdueday"    value="0" />
        <input type="hidden" name="hduemonth"  value="0" />
        <input type="hidden" name="hdueyear"   value="0" />
        <input type="hidden" name="hduehour"   value="0" />
        <input type="hidden" name="hdueminute" value="0" />
    </td>
</tr>

<tr valign="top">
    <td>&nbsp;</td>
    <td><?php print_string('preventlate', 'aca') ?>:
    <?php 
        $options[0] = get_string('no'); $options[1] = get_string('yes');
        choose_from_menu($options, 'preventlate', $form->preventlate, '');
    ?>
    <input type="hidden" name="hpreventlate" value="0" />
    </td>
</tr>

<tr valign="top">
    <td colspan="2">&nbsp;</td>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string("langtype", "aca") ?>:</b></td>
    <td>
    <?php
       $LANG_TYPES = aca_types();
       choose_from_menu($LANG_TYPES, 'langtype', $form->langtype, '');
       helpbutton('types', get_string('acatype', 'aca'), 'aca');
    ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string('showtest', 'aca') ?>:</b></td>
    <td>
    <?php
       $SHOW_OPTIONS[0] = get_string('no'); $SHOW_OPTIONS[1] = get_string('yes');
       $SHOW_OPTIONS[2] = get_string('onlydifferent',"aca");
       choose_from_menu($SHOW_OPTIONS, 'showtest', $form->showtest, '');
       helpbutton('showing', get_string('showing', 'aca'), 'aca');
    ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string('showcopy', 'aca') ?>:</b></td>
    <td>
    <?php
       choose_from_menu($SHOW_OPTIONS, 'showcopy', $form->showcopy, '');
    ?>
    </td>
</tr>

<?php print_standard_coursemodule_settings($form); ?>

</table>
<br />
<center>
<?php
   // Add hidden fields for all the ones not defined on this page
   $assvars = array('course','coursemodule','section','module','modulename','instance','mode',
                    'resubmit','emailteachers','maxbytes',
                    'gradetype','grademax','grademin','graderandval','sourcefile');

   foreach ($assvars as $assname) {
       if (isset($form->$assname)) {
           echo '<input type="hidden" name="'.$assname.'" value="'.s($form->$assname).'" />'."\n";
       }
   }
?>
<input type="submit" value="<?php print_string('next') ?> &raquo;" />
<input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
</center>
</form>

<script type="text/javascript">
<?php 
    if (!$form->timedue) echo "lockoptions('form','dueenable', dueitems);";
    if (!$form->timeavailable) echo "lockoptions('form','availableenable', availableitems);";
?>
</script>

